
<meta charset="utf-8"/>
<title>MarkdownReader.js</title>

<!--
<script src="/StackNote/static/js/lib/marked-2.0.3.js"></script>
<link rel="stylesheet" type="text/css" href="/StackNote/static/css/MarkDown.css" media="all">
v0.1 only js markdown reader;
v0.2 适配：修改为本地 static 文件: 新增三行，搜 myAdd3
	问题：图片不显示，路径是相对 阅读器 md_reader/ ，我希望是相对于 xx.md 文件所在位置
-->
<script src="static/js/lib/marked-2.0.3.js"></script>
<link rel="stylesheet" type="text/css" href="static/css/MarkDown.css" media="all">

<style>
body{margin:0; padding:0;}
.wrapper{
	width:800px;
	margin:0 auto;
}
.header{ padding:5px; color: #aaa; font-size:small; border-bottom:1px dashed #aaa; }
.footer{margin-top:80px; border-top:1px solid black; padding:10px; color: #999;}

.markdown a{
    color: #0969da;
    text-decoration: none;
}

.markdown a:hover{ text-decoration: underline; }
.markdown p{ display: block; }
</style>


<div class="header wrapper">
	filename: <span id="filename"></span>
</div>

<div class="markdown">
	<div id="content" class="wrapper"></div>
</div>

<div class="footer wrapper">
	Powered by <a target="_blank" href="https://github.com/markedjs/marked">markedJS</a> | 
	Fork me on <a target="_blank" href="https://github.com/DawnEve/bioToolKit/tree/dev/JavaScript/markdownReader">Github</a> | 
</div>







<script>
// Tools
//get parameters from URL
function getUrlParam(name) {
	var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
	var r = window.location.search.substr(1).match(reg);  //匹配目标参数
	if (r != null) return unescape(r[2]); return null; //返回参数值
}

//ajax get file contents;
function ajax(fileName, obj){
	var xmlhttp=new XMLHttpRequest(); //1.获取对象
	//2.绑定回调函数
	xmlhttp.onreadystatechange=function(){
		if (xmlhttp.readyState==4 && xmlhttp.status==200){
			//wjl=marked.parse(xmlhttp.responseText);
			obj.innerHTML= marked(xmlhttp.responseText);

			//add base for html static //myAdd3
			var index=fileName.lastIndexOf("/")
			var base_path = fileName.substring(0, index + 1)
			obj.innerHTML+="<base href='"+base_path+"' />"
		}
	}
	//3.设定访问的url
	xmlhttp.open("GET", fileName, true);
	//4.发送请求
	xmlhttp.send();
}



// Action after window OK;
window.onload=function(){
	// get parameter from URL;
	var filename=getUrlParam("file");
	filename = filename || "help.md";
	// update toast
	document.getElementById("filename").innerHTML=filename;
	//render md to html
	ajax(filename, document.getElementById('content'))
}
//document.getElementById('content').innerHTML = marked.parse('# Marked in the browser\n\nRendered by **marked**.');
</script>
